#include<iostream>
#include<vector>
#include<queue>
#include<cstring>
#include<cmath>
#include<map>
#include<set>
#include<cstdio>
#include<algorithm>
#define debug(a) cout<<#a<<"="<<a<<endl;
using namespace std;
const int maxn=1e5;
typedef long long LL;
inline LL read(){LL x=0,f=1;char ch=getchar();	while (!isdigit(ch)){if (ch=='-') f=-1;ch=getchar();}while (isdigit(ch)){x=x*10+ch-48;ch=getchar();}
return x*f;}
LL fa[maxn];
struct edge{
    LL st,ed,cost;
}edges[maxn];
bool cmp(edge A,edge B){
    return A.cost<B.cost;
}
LL find(LL x){
    if(x!=fa[x]) return fa[x]=find(fa[x]);
    else return x;
}
LL cnt=0;
int main(void)
{
  cin.tie(0);std::ios::sync_with_stdio(false);
  LL n;cin>>n;
  for(LL i=1;i<=n+1;i++) fa[i]=i;
  for(LL i=1;i<=n;i++){
        LL x;cin>>x;
        edges[++cnt].st=i;edges[cnt].ed=n+1;edges[cnt].cost=x;
  }
  for(LL i=1;i<=n;i++){
    for(LL j=1;j<=n;j++){
        LL x;cin>>x;
        if(i<=j) continue;
        edges[++cnt].st=i;edges[cnt].ed=j;edges[cnt].cost=x;
    }
  }
  sort(edges+1,edges+1+cnt,cmp);
  LL ans=0;
  for(LL i=1;i<=cnt;i++){
     LL u=find(edges[i].st);LL v=find(edges[i].ed);LL cost=edges[i].cost;
     if(u!=v){
        fa[u]=v;
        ans+=cost;
     }
  }
  cout<<ans<<endl;
return 0;
}
